home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2000 July / macformat-092.iso / Dreamweaver 3 / Configuration / Behaviors / Actions / Check Browser.js < prev    next >
Encoding:
Text File  |  1999-12-01  |  6.3 KB  |  165 lines

  1. // Copyright 1999 Macromedia, Inc. All rights reserved.
  2.  
  3. //*************** GLOBALS VARS *****************
  4.  
  5. var helpDoc = MM.HELP_behCheckBrowser;
  6.  
  7. //******************* BEHAVIOR FUNCTION **********************
  8.  
  9. //Flexible interface allows many choices based on browser type an version.
  10. //If Netscape version meets or exceeds the first version, it can stay on the
  11. //same page of send the page to either of the URLs. Same for IE.
  12. //The function accepts the following arguments:
  13. //  NSvers   - float or integer: Netscape browser version number to check against
  14. //  NSpass   - 0,1,2: where to go if the browser version is the same or higher than NSvers:
  15. //               0 means stay on same page (do nothing)
  16. //               1 means go to theURL
  17. //               2 means go to altURL
  18. //  NSnoPass - 0,1,2: where to go if the browser version is the less than NSvers
  19. //  IEvers   - float or integer: Explorer browser version number to check against
  20. //  IEpass   - 0,1,2: where to go if the browser version is the same or higher than IEvers
  21. //  IEnoPass - 0,1,2: where to go if the browser version is the less than IEvers
  22. //  OBpass   - 0,1,2: where to go if other browser is used
  23. //  theURL   - URL, often a filename, URL encoded. (ex: file.htm, http://www.x.com/y.htm)
  24. //  altURL   - URL, often a filename, URL encoded. (ex: file.htm, http://www.x.com/y.htm)
  25. //
  26. //Gets the client browser version number. Checks if the browser is Netscape.
  27. //If the version number >= NSvers, checks if NSpass > 0, then goes to URL or altURL based
  28. //on NSpass. Then does the same for Internet Explorer. If some other browser is use,
  29. //goes to the URL or altURL based on OBpass. Goes to a URL by setting the
  30. //window.location property. Sets the return value global so this code can override the
  31. //link HREF.
  32.  
  33. function MM_checkBrowser(NSvers,NSpass,NSnoPass,IEvers,IEpass,IEnoPass,OBpass,URL,altURL) { //v3.0
  34.   var newURL='', verStr=navigator.appVersion, app=navigator.appName, version = parseFloat(verStr);
  35.   if (app.indexOf('Netscape') != -1) {
  36.     if (version >= NSvers) {if (NSpass>0) newURL=(NSpass==1)?URL:altURL;}
  37.     else {if (NSnoPass>0) newURL=(NSnoPass==1)?URL:altURL;}
  38.   } else if (app.indexOf('Microsoft') != -1) {
  39.     if (version >= IEvers || verStr.indexOf(IEvers) != -1)
  40.      {if (IEpass>0) newURL=(IEpass==1)?URL:altURL;}
  41.     else {if (IEnoPass>0) newURL=(IEnoPass==1)?URL:altURL;}
  42.   } else if (OBpass>0) newURL=(OBpass==1)?URL:altURL;
  43.   if (newURL) { window.location=unescape(newURL); document.MM_returnValue=false; }
  44. }
  45.  
  46. document.VERSION_MM_checkBrowser = 3.0; //define latest version number for behavior inspector
  47.  
  48. //******************* API **********************
  49.  
  50.  
  51. //Can be used with any tag and any event
  52.  
  53. function canAcceptBehavior(){
  54.   return true;
  55. }
  56.  
  57.  
  58.  
  59. //Returns a Javascript function to be inserted in HTML head with script tags.
  60.  
  61. function behaviorFunction(){
  62.   return "MM_checkBrowser";
  63. }
  64.  
  65.  
  66.  
  67. //Returns fn call to insert in HTML tag <TAG... onEvent='thisFn(arg)'>
  68. //Calls dw.doURLEncoding to encode URLs. Checks validity of all entries.
  69. //For example, if *any* condition uses URL, the URL field cannot be empty.
  70.  
  71. function applyBehavior() {
  72.   var NSvers, IEvers, URL, altURL;
  73.   var NSpass, NSnoPass, IEpass, IEnoPass, OBpass;
  74.  
  75.   with (document.theForm) {  // read all values from form
  76.     NSvers = parseFloat(NSversion.value);
  77.     NSpass = NSpassTest.selectedIndex;
  78.     NSnoPass = NSnoPassTest.selectedIndex;
  79.     IEvers = parseFloat(IEversion.value);
  80.     IEpass = IEpassTest.selectedIndex;
  81.     IEnoPass = IEnoPassTest.selectedIndex;
  82.     OBpass = OBpassTest.selectedIndex;
  83.     URL = dw.doURLEncoding(theURL.value);  //URL encode
  84.     altURL = dw.doURLEncoding(theAltURL.value);  //URL encode
  85.   }
  86.  
  87.   //Check for valid numbers, and URLs exist if required
  88.   if (isNaN(NSvers) || isNaN(IEvers)) return MSG_InvalidVersionNumbers;
  89.   if ((URL=="") && (NSpass==1 || NSnoPass==1 || IEpass==1 || IEnoPass==1 || OBpass==1))
  90.      return MSG_NoURL;
  91.   if ((altURL=="") && (NSpass==2 || NSnoPass==2 || IEpass==2 || IEnoPass==2 || OBpass==2))
  92.      return MSG_NoAltURL;
  93.  
  94.   //Make sure numbers are floats 4 => 4.0
  95.   NSvers = ""+NSvers;
  96.   if (NSvers.indexOf(".") == -1) NSvers += ".0";
  97.   IEvers = ""+IEvers;
  98.   if (IEvers.indexOf(".") == -1) IEvers += ".0";
  99.  
  100.   updateBehaviorFns("MM_checkBrowser");
  101.   return "MM_checkBrowser("+NSvers+","+NSpass+","+NSnoPass+","+IEvers+","+IEpass+","+IEnoPass+
  102.                           ","+OBpass+",'"+URL+"','"+altURL+"')";
  103. }
  104.  
  105.  
  106.  
  107. //Returns a dummy function call to inform Dreamweaver the type of certain behavior
  108. //call arguments. This information is used by DW to fixup behavior args when the
  109. //document is moved or changed.
  110. //
  111. //It is passed an actual function call string generated by applyBehavior(), which
  112. //may have a variable list of arguments, and this should return a matching mask.
  113. //
  114. //The return values are:
  115. //  URL     : argument could be a file path, which DW will update during Save As...
  116. //  NS4.0ref: arg is an object ref that may be changed by Convert Tables to Layers
  117. //  IE4.0ref: arg is an object ref that may be changed by Convert Tables to Layers
  118. //  other...: argument is ignored
  119.  
  120. function identifyBehaviorArguments(fnCallStr) {
  121.   var argArray;
  122.  
  123.   argArray = extractArgs(fnCallStr);
  124.   if (argArray.length == 10) {
  125.     return "other,other,other,other,other,other,other,URL,URL";
  126.   } else {
  127.     return "";
  128.   }
  129. }
  130.  
  131.  
  132.  
  133. //Passed the function call above, takes prior arguments and reloads the UI.
  134. //Converts strings into numbers for list indexes, and decodes URLs.
  135.  
  136. function inspectBehavior(argStr){
  137.   var argArray = extractArgs(argStr);
  138.  
  139.   if (argArray.length == 10) { //function name plus 9 args
  140.     with (document.theForm) {  // set all form values from args
  141.       NSversion.value            =          argArray[1];
  142.       NSpassTest.selectedIndex   = parseInt(argArray[2]);
  143.       NSnoPassTest.selectedIndex = parseInt(argArray[3]);
  144.       IEversion.value            =          argArray[4];
  145.       IEpassTest.selectedIndex   = parseInt(argArray[5]);
  146.       IEnoPassTest.selectedIndex = parseInt(argArray[6]);
  147.       OBpassTest.selectedIndex   = parseInt(argArray[7]);
  148.       theURL.value               = unescape(argArray[8]);
  149.       theAltURL.value            = unescape(argArray[9]);
  150.     }
  151.   }
  152. }
  153.  
  154.  
  155.  
  156. //**************** LOCAL FUNCTIONS ****************
  157.  
  158.  
  159. //Loads a preset list of browser version numbers
  160.  
  161. function initializeUI() {
  162.   document.theForm.theURL.focus(); //set focus on textbox
  163.   document.theForm.theURL.select(); //set insertion point into textbox
  164. }
  165.